package com.ruoyi.back.service.impl

import cn.hutool.core.util.StrUtil
import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper
import com.baomidou.mybatisplus.extension.plugins.pagination.Page
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
import com.ruoyi.app.common.Data
import com.ruoyi.app.common.Ok
import com.ruoyi.back.domain.AppVersionInfo
import com.ruoyi.back.mapper.AppVersionInfoMapper
import com.ruoyi.back.service.AppVersionInfoService
import com.ruoyi.common.core.page.TableSupport
import org.springframework.stereotype.Service

@Service
class AppVersionInfoServiceImpl : ServiceImpl<AppVersionInfoMapper, AppVersionInfo>(), AppVersionInfoService {

    override fun saveAppVersion(appVersionInfo: AppVersionInfo): Data<Boolean> =
        appVersionInfo.id?.run {
            Ok("更新成功", updateById(appVersionInfo))
        } ?: Ok("保存成功", save(appVersionInfo))

    override fun appVersionPage(appVersionInfo: AppVersionInfo): Page<AppVersionInfo> =
        TableSupport.buildPageRequest().let { pageDomain ->
            page(Page(pageDomain.pageNum.toLong(), pageDomain.pageSize.toLong()), KtQueryWrapper(AppVersionInfo::class.java)
                .eq(StrUtil.isNotBlank(appVersionInfo.version), AppVersionInfo::version, appVersionInfo.version))
        }

    override fun removeAppVersionInfo(versionIds: String): Data<Boolean> =
        Ok("批量移除成功", removeByIds(versionIds.split(",")))
}